package com.androidx.p013lv.base.utils;

import android.net.Uri;
import java.net.URL;
import java.net.URLDecoder;
import java.util.LinkedHashMap;
import java.util.Map;

/* renamed from: com.androidx.lv.base.utils.UrlParse */
public class UrlParse {
    public static Map<String, String> getUrlParams(String str) {
        LinkedHashMap linkedHashMap = new LinkedHashMap();
        URL stringToURL = stringToURL(str);
        if (stringToURL == null) {
            return linkedHashMap;
        }
        try {
            String query = stringToURL.getQuery();
            if (query == null) {
                return linkedHashMap;
            }
            if (query.contains("url=")) {
                int indexOf = query.indexOf("url=");
                linkedHashMap.put("url", URLDecoder.decode(query.substring(indexOf + 4), "UTF-8"));
                query = query.substring(0, indexOf);
            }
            if (query.length() > 0) {
                String[] split = query.split("&");
                for (String str2 : split) {
                    int indexOf2 = str2.indexOf("=");
                    if (indexOf2 > 0 && indexOf2 < str2.length() - 1) {
                        linkedHashMap.put(URLDecoder.decode(str2.substring(0, indexOf2), "UTF-8"), URLDecoder.decode(str2.substring(indexOf2 + 1), "UTF-8"));
                    }
                }
            }
            return linkedHashMap;
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static String getUrlParamStr(String str) {
        URL stringToURL = stringToURL(str);
        if (stringToURL == null) {
            return "";
        }
        try {
            return stringToURL.getQuery();
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
    }

    public static String getUrlHostAndPath(String str) {
        return str.contains("?") ? str.substring(0, str.indexOf("?")) : str;
    }

    public static String getUriParam(Uri uri, String str) {
        String queryParameter;
        if (uri == null || str == null || str.length() == 0 || (queryParameter = uri.getQueryParameter(str)) == null) {
            return "";
        }
        return queryParameter;
    }

    public static int getIntUriParam(Uri uri, String str) {
        if (!(uri == null || str == null || str.length() == 0)) {
            try {
                String queryParameter = uri.getQueryParameter(str);
                if (queryParameter != null) {
                    if (queryParameter.length() != 0) {
                        return Integer.parseInt(queryParameter);
                    }
                }
                return 0;
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return 0;
    }

    private static URL stringToURL(String str) {
        if (!(str == null || str.length() == 0 || !str.contains("://"))) {
            try {
                return new URL("http" + str.substring(str.indexOf("://")));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return null;
    }
}
